home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / testinit / RCS / testinit.c,v < prev   
Encoding:
Text File  |  1992-07-17  |  21.3 KB  |  992 lines

  1. head     1.13;
  2. branch   ;
  3. access   ;
  4. symbols  srv030:1.13 srv027:1.13 srv026:1.13 srv024:1.13 srv021:1.13 srv018:1.13 srv014:1.13 srv010:1.13 srv008:1.13 srv007:1.13 srv006:1.13 srv004:1.13 echo:1.8.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.13
  10. date     92.03.23.15.10.43;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.12;
  13.  
  14. 1.12
  15. date     92.01.22.13.24.30;  author kupfer;  state Exp;
  16. branches ;
  17. next     1.11;
  18.  
  19. 1.11
  20. date     91.12.19.13.26.50;  author kupfer;  state Exp;
  21. branches ;
  22. next     1.10;
  23.  
  24. 1.10
  25. date     91.10.04.12.27.21;  author kupfer;  state Exp;
  26. branches ;
  27. next     1.9;
  28.  
  29. 1.9
  30. date     91.09.25.23.45.27;  author kupfer;  state Exp;
  31. branches ;
  32. next     1.8;
  33.  
  34. 1.8
  35. date     91.09.19.19.03.52;  author kupfer;  state Exp;
  36. branches 1.8.1.1;
  37. next     1.7;
  38.  
  39. 1.7
  40. date     91.09.03.12.21.51;  author kupfer;  state Exp;
  41. branches ;
  42. next     1.6;
  43.  
  44. 1.6
  45. date     91.08.30.16.06.00;  author kupfer;  state Exp;
  46. branches ;
  47. next     1.5;
  48.  
  49. 1.5
  50. date     91.08.25.22.06.17;  author kupfer;  state Exp;
  51. branches ;
  52. next     1.4;
  53.  
  54. 1.4
  55. date     91.08.12.16.13.13;  author kupfer;  state Exp;
  56. branches ;
  57. next     1.3;
  58.  
  59. 1.3
  60. date     91.07.22.11.37.32;  author kupfer;  state Exp;
  61. branches ;
  62. next     1.2;
  63.  
  64. 1.2
  65. date     91.07.19.15.22.50;  author kupfer;  state Exp;
  66. branches ;
  67. next     1.1;
  68.  
  69. 1.1
  70. date     91.07.18.14.32.34;  author kupfer;  state Exp;
  71. branches ;
  72. next     ;
  73.  
  74. 1.8.1.1
  75. date     91.09.19.22.28.02;  author kupfer;  state Exp;
  76. branches ;
  77. next     ;
  78.  
  79.  
  80. desc
  81. @Simple test client, corresponding to /etc/init.
  82. @
  83.  
  84.  
  85. 1.13
  86. log
  87. @Add console support.
  88. @
  89. text
  90. @/* 
  91.  * testinit.c --
  92.  *
  93.  *    Test initial user program.
  94.  *
  95.  * Copyright 1991 Regents of the University of California
  96.  * Permission to use, copy, modify, and distribute this
  97.  * software and its documentation for any purpose and without
  98.  * fee is hereby granted, provided that this copyright
  99.  * notice appears in all copies.  The University of California
  100.  * makes no representations about the suitability of this
  101.  * software for any purpose.  It is provided "as is" without
  102.  * express or implied warranty.
  103.  */
  104.  
  105. #ifndef lint
  106. static char rcsid[] = "$Header: /user5/kupfer/spriteserver/tests/testinit/RCS/testinit.c,v 1.12 92/01/22 13:24:30 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  107. #endif /* not lint */
  108.  
  109. #include <cfuncproto.h>
  110. #include <errno.h>
  111. #include <pwd.h>
  112. #include <stdio.h>
  113. #include <stdlib.h>
  114. #include <string.h>
  115. #include <sys.h>
  116. #include <sys/file.h>
  117. #include <sys/types.h>
  118. #include <sys/wait.h>
  119. #include <test.h>
  120. #include <unistd.h>
  121.  
  122. #define CONSOLE    "/dev/console"    /* name of console device */
  123.  
  124. extern void msleep();
  125. static void SetID _ARGS_((void));
  126.  
  127.  
  128. /*
  129.  *----------------------------------------------------------------------
  130.  *
  131.  * main --
  132.  *
  133.  *    For now, just call a shell.  
  134.  *
  135.  * Results:
  136.  *    None.
  137.  *
  138.  * Side effects:
  139.  *    None.
  140.  *
  141.  *----------------------------------------------------------------------
  142.  */
  143.     
  144. int
  145. main(argc, argv)
  146.     int argc;
  147.     char **argv;
  148. {
  149.     pid_t pid;
  150.     char *shellName = "cmds.sprited/psh";
  151.     int i;
  152.     union wait exitStatus;
  153.  
  154.     Test_PutDecimal(argc);
  155.     Test_PutMessage(" arguments: \n");
  156.     for (i = 0; i < argc; i++) {
  157.     Test_PutMessage(argv[i]);
  158.     Test_PutMessage("\n");
  159.     }
  160.     if (argc >= 2) {
  161.     shellName = argv[1];
  162.     }
  163.  
  164.     /* 
  165.      * Open the console, which will enable use of stdio.  If that fails, 
  166.      * bail out.
  167.      */
  168.     if ((open(CONSOLE, O_RDONLY, 0) != 0)
  169.         || (open(CONSOLE, O_WRONLY, 0) != 1)
  170.         || (open(CONSOLE, O_WRONLY, 0) != 2)) {
  171.     Test_PutMessage("Couldn't open console: ");
  172.     Test_PutMessage(strerror(errno));
  173.     Test_PutMessage(".\n");
  174.     exit(2);
  175.     }
  176.  
  177. /* 
  178.  * Redefine the Test_ calls to use stdio.
  179.  */
  180. #include <testRedef.h>
  181.  
  182.     /* 
  183.      * cd to a test directory, then start up the shell or whatever program 
  184.      * we're suppposed to run.
  185.      */
  186.     if (chdir("/users/kupfer") < 0) {
  187.     Test_PutMessage("Can't chdir to /users/kupfer: ");
  188.     Test_PutMessage(strerror(errno));
  189.     Test_PutMessage("\n");
  190.     goto bailOut;
  191.     }
  192.  
  193.     pid = fork();
  194.     if (pid < 0) {
  195.     Test_PutMessage("Fork failed: ");
  196.     Test_PutMessage(strerror(errno));
  197.     Test_PutMessage("\n");
  198.     goto bailOut;
  199.     } 
  200.     if (pid == 0) {
  201.     char *args[2];
  202.  
  203.     /* Change the user ID to be non-root. */
  204.     SetID();
  205.  
  206.     args[0] = shellName;
  207.     args[1] = 0;
  208. #if 0
  209.     Test_PutMessage("I'm the child (pid ");
  210.     Test_PutHex(getpid());
  211.     Test_PutMessage(")\n");
  212. #endif
  213.     if (execv(shellName, args) < 0) {
  214.         Test_PutMessage("Couldn't exec `");
  215.         Test_PutMessage(shellName);
  216.         Test_PutMessage("': ");
  217.         Test_PutMessage(strerror(errno));
  218.         Test_PutMessage("\n");
  219.         exit(1);
  220.     }
  221.     exit(0);
  222.     } else {
  223. #if 0
  224.     Test_PutMessage("Child is pid ");
  225.     Test_PutHex(pid);
  226.     Test_PutMessage("\n");
  227. #endif
  228.     pid = wait(&exitStatus);
  229.     Test_PutMessage("process ");
  230.     Test_PutHex(pid);
  231.     Test_PutMessage(" finished, code ");
  232.     Test_PutDecimal(exitStatus.w_retcode);
  233.     if (exitStatus.w_termsig != 0) {
  234.         Test_PutMessage(", signal ");
  235.         Test_PutDecimal(exitStatus.w_termsig);
  236.     }
  237.     Test_PutMessage(".\n");
  238.     }
  239.  
  240.  bailOut:
  241.     (void)Sys_Shutdown(SYS_HALT|SYS_KILL_PROCESSES|SYS_WRITE_BACK, NULL);
  242. }
  243.  
  244.  
  245. /*
  246.  *----------------------------------------------------------------------
  247.  *
  248.  * SetID --
  249.  *
  250.  *    Set the user ID of the process to something less potentially 
  251.  *    harmful than root.  
  252.  *
  253.  * Results:
  254.  *    None.
  255.  *
  256.  * Side effects:
  257.  *    None.
  258.  *
  259.  *----------------------------------------------------------------------
  260.  */
  261.  
  262. static void
  263. SetID()
  264. {
  265.     struct passwd *passwdEntPtr; /* password entry for designated user ID */
  266.     char *user = "kupfer";
  267.     uid_t expectedUid = 891;
  268.  
  269.     passwdEntPtr = getpwnam(user);
  270.     if (passwdEntPtr == NULL) {
  271.     fprintf(stderr, "Warning: couldn't find passwd entry for %s.\n",
  272.         user);
  273.     } else if (passwdEntPtr->pw_uid != expectedUid) {
  274.     fprintf(stderr, "Warning: expected uid %d for %s, got %d.\n",
  275.         expectedUid, user, passwdEntPtr->pw_uid);
  276.     }
  277.  
  278.     if (setuid(expectedUid) < 0) {
  279.     fprintf(stderr, "Couldn't change user ID to %d: %s\n",
  280.         expectedUid, strerror(errno));
  281.     }
  282. }
  283. @
  284.  
  285.  
  286. 1.12
  287. log
  288. @Make easier to use on top of Sprite file system.  Track changes to
  289. Sys_Shutdown.
  290. @
  291. text
  292. @d17 1
  293. a17 1
  294. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/tests/testinit/RCS/testinit.c,v 1.11 91/12/19 13:26:50 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  295. d27 1
  296. d33 2
  297. d44 1
  298. a44 2
  299.  *    For now, just call a test routine.  Eventually will exec the init 
  300.  *    program. 
  301. d61 1
  302. a61 1
  303.     char *realInitName = "cmds.sprited/psh"; /* name of program to exec */
  304. d72 14
  305. a85 1
  306.     realInitName = argv[1];
  307. d88 5
  308. d117 1
  309. a117 1
  310.     args[0] = realInitName;
  311. d124 1
  312. a124 1
  313.     if (execv(realInitName, args) < 0) {
  314. d126 1
  315. a126 1
  316.         Test_PutMessage(realInitName);
  317. @
  318.  
  319.  
  320. 1.11
  321. log
  322. @Make psh the default program to run.  Set uid to kupfer before execing
  323. the program.  Turn on FS write-back when calling Sys_Shutdown.
  324. @
  325. text
  326. @d17 1
  327. a17 1
  328. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/tests/testinit/RCS/testinit.c,v 1.10 91/10/04 12:27:21 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  329. d59 1
  330. a59 1
  331.     char *realInitName = "psh"; /* name of program to exec */
  332. d73 11
  333. d132 1
  334. a132 1
  335.     (void)Sys_Shutdown(SYS_HALT|SYS_KILL_PROCESSES|SYS_WRITE_BACK);
  336. @
  337.  
  338.  
  339. 1.10
  340. log
  341. @Move Mach knowledge & emulation functions into library.  Change from
  342. "copy file" framework to fork/exec framework.
  343. @
  344. text
  345. @d17 1
  346. a17 1
  347. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/src/emulator/RCS/emuMain.c,v 1.9 91/09/25 23:45:27 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  348. d20 1
  349. d22 2
  350. d33 1
  351. d59 1
  352. a59 1
  353.     char *secondName = "second"; /* name of program to exec */
  354. d70 1
  355. a70 1
  356.     secondName = argv[1];
  357. d82 5
  358. a86 1
  359.     args[0] = secondName;
  360. d88 1
  361. d92 2
  362. a93 1
  363.     if (execv(secondName, args) < 0) {
  364. d95 1
  365. a95 1
  366.         Test_PutMessage(secondName);
  367. d103 1
  368. d107 1
  369. d121 1
  370. a121 1
  371.     (void)Sys_Shutdown(SYS_HALT|SYS_KILL_PROCESSES);
  372. d124 39
  373. @
  374.  
  375.  
  376. 1.9
  377. log
  378. @Move Mach knowledge into C library.
  379. @
  380. text
  381. @d2 1
  382. a2 1
  383.  * emuMain.c --
  384. d4 1
  385. a4 1
  386.  *    Framework for shared emulator library.
  387. d17 1
  388. a17 1
  389. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/src/emulator/RCS/emuMain.c,v 1.8 91/09/19 19:03:52 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  390. d20 2
  391. a21 5
  392. #include <bstring.h>
  393. #include <ctype.h>
  394. #include <spriteEmu.h>
  395. #include <status.h>
  396. #include <stdio.h>
  397. a22 1
  398. #include <proc.h>
  399. d24 2
  400. a25 1
  401. #include <tempFs.h>
  402. d27 1
  403. a27 1
  404. #include <vm.h>
  405. d29 1
  406. a29 1
  407. /* Forward references */
  408. a30 4
  409. static int GetLength _ARGS_((char *fileName));
  410. static void MapFile _ARGS_((char *fileName, boolean_t readOnly,
  411.                 int length, Address *startAddrPtr));
  412.  
  413. d54 4
  414. a57 7
  415.     char *fromName = "testInput"; /* name of file to copy from */
  416.     char *fromBuffer;        /* mapped "from" file */
  417.     char *toName = "testOutput"; /* name of file to copy to */
  418.     char *toBuffer;        /* mapped "to" file */
  419.     int fileLength;
  420.  
  421.     SpriteEmu_Init();
  422. d59 5
  423. a63 5
  424.     fileLength = GetLength(fromName);
  425. #if 0
  426.     if (fileLength < 0) {
  427.     Test_PutMessage("bailing out.\n");
  428.     goto bailOut;
  429. d65 2
  430. a66 7
  431. #endif
  432.  
  433.     MapFile(fromName, TRUE, fileLength, &fromBuffer);
  434.     MapFile(toName, FALSE, fileLength, &toBuffer);
  435.  
  436.     if (fromBuffer != 0 && toBuffer != 0) {
  437.     bcopy(fromBuffer, toBuffer, fileLength);
  438. d69 4
  439. a72 34
  440.     (void)Sys_Shutdown(SYS_HALT|SYS_KILL_PROCESSES);
  441. }
  442.  
  443.  
  444. /*
  445.  *----------------------------------------------------------------------
  446.  *
  447.  * MapFile --
  448.  *
  449.  *    Map the named file into our address space.
  450.  *
  451.  * Results:
  452.  *    Fills in the starting location, which is set to 0 
  453.  *    if there was a problem.
  454.  *
  455.  * Side effects:
  456.  *    None.
  457.  *
  458.  *----------------------------------------------------------------------
  459.  */
  460.  
  461. static void
  462. MapFile(fileName, readOnly, length, startAddrPtr)
  463.     char *fileName;        /* name of file to map */
  464.     Boolean readOnly;        /* map read-only or read-write? */
  465.     int length;            /* number of bytes to map */
  466.     Address *startAddrPtr;    /* OUT: where the file was mapped to */
  467. {
  468.     ReturnStatus status;
  469.  
  470.     status = Vm_MapFile(fileName, readOnly, 0, length, startAddrPtr);
  471.     if (status != SUCCESS) {
  472.     Test_PutMessage("Couldn't map file: ");
  473.     Test_PutMessage(Stat_GetMsg(status));
  474. d74 21
  475. a94 33
  476.     *startAddrPtr = 0;
  477.     }
  478. }
  479.  
  480.  
  481. /*
  482.  *----------------------------------------------------------------------
  483.  *
  484.  * GetLength --
  485.  *
  486.  *    Get the length of a file.
  487.  *
  488.  * Results:
  489.  *    Returns the length of the file, in bytes.  Returns -1 if there 
  490.  *    was an error.
  491.  *
  492.  * Side effects:
  493.  *    None.
  494.  *
  495.  *----------------------------------------------------------------------
  496.  */
  497.  
  498. static int
  499. GetLength(fileName)
  500.     char *fileName;
  501. {
  502.     ReturnStatus status;
  503.     int length;
  504.  
  505.     status = TempFs_Length(fileName, &length);
  506.     if (status != SUCCESS) {
  507.     Test_PutMessage("Couldn't get file length: ");
  508.     Test_PutMessage(Stat_GetMsg(status));
  509. d96 10
  510. a105 1
  511.     return -1;
  512. d108 2
  513. a109 1
  514.     return length;
  515. d111 1
  516. @
  517.  
  518.  
  519. 1.8
  520. log
  521. @Sys_Shutdown now takes flags.  Lint.
  522. @
  523. text
  524. @d2 1
  525. a2 1
  526.  * client.c --
  527. d4 1
  528. a4 1
  529.  *    Test program for printf server.
  530. d17 1
  531. a17 1
  532. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/emulator/RCS/emuMain.c,v 1.7 91/09/03 12:21:51 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  533. d22 1
  534. a22 2
  535. #include <mach.h>
  536. #include <mach_error.h>
  537. d26 5
  538. a30 3
  539. #include <user/proc.h>
  540. #include <user/sys.h>
  541. #include <spriteSrv.h>
  542. a31 2
  543. mach_port_t serverPort;        /* port for making Sprite requests */
  544.  
  545. d38 18
  546. d57 3
  547. a59 1
  548. main()
  549. a60 4
  550.     kern_return_t kernStatus;
  551. #ifdef SHARED_ERROR_REGION
  552.     int *errorPtr = (int *)PROC_SHARED_REGION_START;
  553. #endif
  554. d67 1
  555. a67 7
  556.     kernStatus = task_get_bootstrap_port(mach_task_self(), &serverPort);
  557.     if (kernStatus != KERN_SUCCESS) {
  558. #if SHARED_ERROR_REGION
  559.     *errorPtr = kernStatus;
  560. #endif
  561.     thread_suspend(mach_thread_self());    
  562.     }
  563. d72 1
  564. a72 1
  565.     Test_PutMessage(serverPort, "bailing out.\n");
  566. d84 1
  567. a84 1
  568.     Sys_Shutdown(serverPort, SYS_HALT|SYS_KILL_PROCESSES);
  569. d108 1
  570. a108 1
  571.     boolean_t readOnly;        /* map read-only or read-write? */
  572. a111 1
  573.     kern_return_t kernStatus;
  574. d114 5
  575. a118 6
  576.     kernStatus = Vm_MapFileStub(serverPort, fileName, strlen(fileName)+1,
  577.                 readOnly, 0, length, &status, startAddrPtr);
  578.     if (kernStatus != KERN_SUCCESS) {
  579.     Test_PutMessage(serverPort, "Couldn't map file: ");
  580.     Test_PutMessage(serverPort, mach_error_string(kernStatus));
  581.     Test_PutMessage(serverPort, "\n");
  582. a119 5
  583.     } else if (status != SUCCESS) {
  584.     Test_PutMessage(serverPort, "Couldn't map file: ");
  585.     Test_PutMessage(serverPort, Stat_GetMsg(status));
  586.     Test_PutMessage(serverPort, "\n");
  587.     *startAddrPtr = 0;
  588. a146 1
  589.     kern_return_t kernStatus;
  590. d148 1
  591. a148 8
  592.     kernStatus = TempFs_LengthStub(serverPort, fileName, strlen(fileName)+1,
  593.                    &status, &length);
  594.     if (kernStatus != KERN_SUCCESS) {
  595.     Test_PutMessage(serverPort, "Couldn't get file length: ");
  596.     Test_PutMessage(serverPort, mach_error_string(kernStatus));
  597.     Test_PutMessage(serverPort, "\n");
  598.     return -1;
  599.     }
  600. d150 3
  601. a152 3
  602.     Test_PutMessage(serverPort, "Couldn't get file length: ");
  603.     Test_PutMessage(serverPort, Stat_GetMsg(status));
  604.     Test_PutMessage(serverPort, "\n");
  605. @
  606.  
  607.  
  608. 1.8.1.1
  609. log
  610. @Use as echo program--print a prompt, get a string, and write the string.
  611. Could use better EOF detection (just looks for leading ".", doesn't
  612. check if there are any other characters in the line).
  613. @
  614. text
  615. @d17 1
  616. a17 1
  617. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/src/emulator/RCS/emuMain.c,v 1.8 91/09/19 19:03:52 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  618. d35 3
  619. a37 1
  620. static void Failed _ARGS_((char *complaint, kern_return_t errorCode));
  621. d46 5
  622. a50 3
  623.     int firstGuard = 9876;
  624.     char buffer[9000];
  625.     int secondGuard = 4242;
  626. d60 5
  627. a64 21
  628.     for (;;) {
  629.     (void)Test_PutMessage(serverPort, "Type something: ");
  630.     kernStatus = Test_GetString(serverPort, buffer, sizeof(buffer));
  631.     if (kernStatus != KERN_SUCCESS) {
  632.         Failed("Couldn't get input", kernStatus);
  633.         goto bailOut;
  634.     }
  635.     if (firstGuard != 9876) {
  636.         Test_PutMessage(serverPort, "first guard blown away\n");
  637.     }
  638.     if (secondGuard != 4242) {
  639.         Test_PutMessage(serverPort, "second guard blown away\n");
  640.     }
  641.     if (buffer[0] == '.' || buffer[0] == '\0') {
  642.         break;
  643.     }
  644.     kernStatus = Test_PutString(serverPort, buffer, sizeof(buffer));
  645.     if (kernStatus != KERN_SUCCESS) {
  646.         Failed("Couldn't echo the string", kernStatus);
  647.         goto bailOut;
  648.     }
  649. d66 8
  650. a74 1
  651.  bailOut:
  652. d82 1
  653. a82 1
  654.  * Failed --
  655. d84 1
  656. a84 1
  657.  *    Print an error message for a MIG call, clumsily.
  658. d87 4
  659. d93 40
  660. d139 3
  661. a141 4
  662. static void
  663. Failed(complaint, errorCode)
  664.     char *complaint;
  665.     kern_return_t errorCode;
  666. d143 20
  667. a162 4
  668.     (void)Test_PutMessage(serverPort, complaint);
  669.     (void)Test_PutMessage(serverPort, ": ");
  670.     (void)Test_PutMessage(serverPort, mach_error_string(errorCode));
  671.     (void)Test_PutMessage(serverPort, "\n");
  672. @
  673.  
  674.  
  675. 1.7
  676. log
  677. @Use <> for sprited header files.  Lint.
  678. @
  679. text
  680. @d17 1
  681. a17 1
  682. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/emulator/RCS/emuMain.c,v 1.6 91/08/30 16:06:00 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  683. d28 1
  684. a30 2
  685. #define SHARED_ERROR_REGION    1
  686.  
  687. a35 1
  688. static void MakeFile _ARGS_((char *fileName));
  689. a37 2
  690. static void PrintBuffer _ARGS_((char *fileName, char *bufPtr, int length));
  691. static void WriteToBuffer _ARGS_((char *fileName, char *bufPtr, int length));
  692. d75 1
  693. a75 2
  694.  bailOut:
  695.     Sys_Shutdown(serverPort);
  696. @
  697.  
  698.  
  699. 1.6
  700. log
  701. @Put back in support for shared area for low-level comm. with server.
  702. @
  703. text
  704. @d17 1
  705. a17 1
  706. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/client/RCS/client.c,v 1.5 91/08/25 22:06:17 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  707. d20 1
  708. d26 1
  709. d28 1
  710. a28 1
  711. #include "spriteSrv.h"
  712. d43 1
  713. @
  714.  
  715.  
  716. 1.5
  717. log
  718. @Copy from "testInput" to "testOutput" by mapping the files and doing a
  719. bcopy.
  720. @
  721. text
  722. @d17 1
  723. a17 1
  724. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/client/RCS/client.c,v 1.4 91/08/12 16:13:13 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  725. d28 2
  726. d44 1
  727. d46 1
  728. d55 1
  729. d57 1
  730. @
  731.  
  732.  
  733. 1.4
  734. log
  735. @Snapshot.  Program maps a fixed-length file, scribbles over it, and reads it back.
  736. @
  737. text
  738. @d17 1
  739. a17 1
  740. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/client/RCS/client.c,v 1.3 91/07/22 11:37:32 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  741. d43 4
  742. a46 2
  743.     char *fileName = "/usr0/kupfer/testInput"; /* name of file to map */
  744.     char *firstTime, *secondTime; /* buffers for mapped files */
  745. d55 2
  746. a56 1
  747.     fileLength = GetLength(fileName);
  748. d58 1
  749. d61 1
  750. d63 2
  751. a64 2
  752.     MapFile(fileName, FALSE, fileLength, &firstTime);
  753.     WriteToBuffer(fileName, firstTime, fileLength);
  754. d66 2
  755. a67 16
  756.     MapFile(fileName, TRUE, fileLength, &secondTime);
  757.     PrintBuffer(fileName, secondTime, fileLength);
  758.  
  759.     kernStatus = vm_deallocate(mach_task_self(), (vm_address_t)firstTime,
  760.                    fileLength);
  761.     if (kernStatus != KERN_SUCCESS) {
  762.     Test_PutMessage(serverPort, "Couldn't deallocate first buffer: ");
  763.     Test_PutMessage(serverPort, mach_error_string(kernStatus));
  764.     Test_PutMessage(serverPort, "\n");
  765.     }
  766.     kernStatus = vm_deallocate(mach_task_self(), (vm_address_t)secondTime,
  767.                    fileLength);
  768.     if (kernStatus != KERN_SUCCESS) {
  769.     Test_PutMessage(serverPort, "Couldn't deallocate second buffer: ");
  770.     Test_PutMessage(serverPort, mach_error_string(kernStatus));
  771.     Test_PutMessage(serverPort, "\n");
  772. a69 3
  773.     MapFile(fileName, TRUE, fileLength, &secondTime);
  774.     PrintBuffer(fileName, secondTime, fileLength);
  775.  
  776. a77 46
  777.  * PrintBuffer --
  778.  *
  779.  *    Copy the given buffer to stdout.
  780.  *
  781.  * Results:
  782.  *    None.
  783.  *
  784.  * Side effects:
  785.  *    Maps the file into the process address space and leaves it 
  786.  *    there. 
  787.  *
  788.  *----------------------------------------------------------------------
  789.  */
  790.  
  791. static void
  792. PrintBuffer(fileName, bufPtr, length)
  793.     char *fileName;        /* name of file mapped into the buffer */
  794.     char *bufPtr;        /* start of buffer */
  795.     int length;            /* number of bytes to print */
  796. {
  797.     char *chPtr;        /* pointer into the file */
  798.     char buf[2];        /* buffer for 1 character & null */
  799.  
  800.     buf[1] = '\0';
  801.     Test_PutMessage(serverPort, "-- ");
  802.     Test_PutMessage(serverPort, fileName);
  803.     Test_PutMessage(serverPort, " (");
  804.     Test_PutHex(serverPort, bufPtr);
  805.     Test_PutMessage(serverPort, " + ");
  806.     Test_PutDecimal(serverPort, length);
  807.     Test_PutMessage(serverPort, " bytes) --\n");
  808.     for (chPtr = bufPtr; chPtr < bufPtr + length; chPtr++) {
  809.     if (isascii(*chPtr) && (isprint(*chPtr) || isspace(*chPtr))) {
  810.         buf[0] = *chPtr;
  811.         Test_PutMessage(serverPort, buf);
  812.     } else {
  813.         Test_PutMessage(serverPort, "\\");
  814.         Test_PutOctal(serverPort, *chPtr);
  815.     }
  816.     }
  817. }
  818.  
  819.  
  820. /*
  821.  *----------------------------------------------------------------------
  822.  *
  823. a113 38
  824.     }
  825. }
  826.  
  827.  
  828. /*
  829.  *----------------------------------------------------------------------
  830.  *
  831.  * WriteToBuffer --
  832.  *
  833.  *    Scribble over a buffer.
  834.  *
  835.  * Results:
  836.  *    None.
  837.  *
  838.  * Side effects:
  839.  *    Fills the first "length" characters of the buffer with a 
  840.  *    string of characters.
  841.  *
  842.  *----------------------------------------------------------------------
  843.  */
  844.  
  845. static void
  846. WriteToBuffer(fileName, bufferPtr, length)
  847.     char *fileName;        /* name of the file (unused) */
  848.     char *bufferPtr;        /* start of the buffer */
  849.     int length;            /* number of characters to overwrite */
  850. {
  851.     char *chPtr;
  852.     int numChars;        /* number of characters written */
  853.  
  854.     /* Write with a pattern like "0.........1.........2..." */
  855.     for (chPtr = bufferPtr, numChars = 0; numChars < length;
  856.          chPtr++, numChars++) {
  857.     if ((numChars % 10) == 0) {
  858.         *chPtr = '0' + ((numChars / 10) % 10);
  859.     } else {
  860.         *chPtr = '.';
  861.     }
  862. @
  863.  
  864.  
  865. 1.3
  866. log
  867. @Use shutdown call instead of going into infinite loop.
  868. @
  869. text
  870. @d17 1
  871. a17 1
  872. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/client/RCS/client.c,v 1.2 91/07/19 15:22:50 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  873. d20 1
  874. d22 2
  875. a23 1
  876. #include <userProc.h>
  877. d25 1
  878. d28 2
  879. d32 6
  880. a37 1
  881. static void CheckStatus();
  882. d41 5
  883. a45 4
  884.     mach_port_t serverPort;
  885.     kern_return_t status;
  886.     int i;
  887.     int *errorPtr = (int *)SHARED_REGION_START;
  888. d47 3
  889. a49 3
  890.     status = task_get_bootstrap_port(mach_task_self(), &serverPort);
  891.     if (status != KERN_SUCCESS) {
  892.     *errorPtr = status;
  893. d53 24
  894. a76 7
  895.     for (i = 0; i <= 20; i++) {
  896.     Sys_PutDecimal(serverPort, i);
  897.     Sys_PutMessage(serverPort, " ");
  898.     Sys_PutOctal(serverPort, i);
  899.     Sys_PutMessage(serverPort, " ");
  900.     Sys_PutHex(serverPort, i);
  901.     Sys_PutMessage(serverPort, "\n");
  902. d79 2
  903. a80 1
  904.     Sys_PutMessage(serverPort, "Hi, mom\n");
  905. d82 1
  906. d84 171
  907. @
  908.  
  909.  
  910. 1.2
  911. log
  912. @Changes so can be started by server.
  913. @
  914. text
  915. @d17 1
  916. a17 1
  917. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/client/RCS/client.c,v 1.1 91/07/18 14:32:34 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  918. d53 1
  919. a53 2
  920.  loop:
  921.     goto loop;
  922. @
  923.  
  924.  
  925. 1.1
  926. log
  927. @Initial revision
  928. @
  929. text
  930. @d17 1
  931. a17 1
  932. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.5 91/02/09 13:24:44 ouster Exp $ SPRITE (Berkeley)";
  933. d21 1
  934. a22 1
  935. #include <servers/netname.h>
  936. d34 1
  937. d36 1
  938. a36 2
  939.     status = netname_look_up(name_server_port, "*", "Sprite",
  940.                  &serverPort);
  941. d38 2
  942. a39 3
  943.     fprintf(stderr, "Can't get Sprite server port: %s\n",
  944.         mach_error_string(status));
  945.     exit(1);
  946. d43 6
  947. a48 6
  948.     CheckStatus(Sys_PutDecimal(serverPort, i));
  949.     CheckStatus(Sys_PutMessage(serverPort, " "));
  950.     CheckStatus(Sys_PutOctal(serverPort, i));
  951.     CheckStatus(Sys_PutMessage(serverPort, " "));
  952.     CheckStatus(Sys_PutHex(serverPort, i));
  953.     CheckStatus(Sys_PutMessage(serverPort, "\n"));
  954. d51 1
  955. a51 1
  956.     CheckStatus(Sys_PutMessage(serverPort, "Hi, mom\n"));
  957. d53 2
  958. a54 1
  959.     return 0;
  960. a55 30
  961.  
  962.  
  963. /*
  964.  *----------------------------------------------------------------------
  965.  *
  966.  * CheckStatus --
  967.  *
  968.  *    Verify that an operation succeeded.  Complain and exit if 
  969.  *    there was an error.
  970.  *
  971.  * Results:
  972.  *    None.
  973.  *
  974.  * Side effects:
  975.  *    None.
  976.  *
  977.  *----------------------------------------------------------------------
  978.  */
  979.  
  980. static void
  981. CheckStatus(status)
  982.     kern_return_t status;
  983. {
  984.     if (status != KERN_SUCCESS) {
  985.     fprintf(stderr, "Couldn't do RPC: %s\n",
  986.         mach_error_string(status));
  987.     exit(1);
  988.     }
  989. }
  990.  
  991. @
  992.